package net.sf.fc.io.ch;

import java.io.File;

/**
 * Class that wraps a RenameFileCopyHelper and an UpdateFileCopyHelper. If the destination file is newer than the
 * source file, it will rename it. Otherwise, handleExistingFile will return Action.SKIP.
 *
 * @author David Armstrong
 *
 */
public class UpdateRenameFileCopyHelper extends RenameFileCopyHelper {

    private final RenameFileCopyHelper renameFileCopyHelper;
    private final FileCopyHelper updateFileCopyHelper;

    public UpdateRenameFileCopyHelper(RenameFileCopyHelper renameFileCopyHelper) {
        this.renameFileCopyHelper = renameFileCopyHelper;
        updateFileCopyHelper = new UpdateFileCopyHelper();
    }

    @Override
    public File createNewFile(File dest) {
        return renameFileCopyHelper.createNewFile(dest);
    }

    @Override
    public Action handleExistingFile(File source, File dest) {
        Action action = updateFileCopyHelper.handleExistingFile(source, dest);
        if(action.equals(Action.CONTINUE)) {
            action = renameFileCopyHelper.handleExistingFile(source, dest);
        }
        return action;
    }

    @Override
    public boolean cancel() {
        // TODO Auto-generated method stub
        return false;
    }

}
